206. 反转链表
给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。

https://leetcode.cn/problems/reverse-linked-list/description/



//迭代
struct ListNode* reverseList(struct ListNode* head)
{
    if(head==NULL)
    {
        return NULL;
    }

    struct ListNode*n1,*n2,*n3;
    n1=NULL;
    n2=head;
    n3=head->next;
    while(n2)
    {
        n2->next=n1;
        n1=n2;
        n2=n3;
        if(n3)
        {
            n3=n3->next;   
        }
    }
    return n1;

}

//头插法

struct ListNode* reverseList(struct ListNode* head)
{
    struct ListNode*rhead=NULL;
    struct ListNode*cur=head;
    while(cur)
    {
        struct ListNode*next=cur->next;
        //头插
        cur->next=rhead;
        rhead=cur;
        cur=next;
    }

    return rhead;

}